package com.burst.reptile.framework.config;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;

/**
 * mp的插件拓展和资源扫描
 * @author wujin
 * @date: 2019年11月4日 下午2:47:15
 */
@Configuration
@MapperScan(basePackages = {"com.burst.reptile.modular.*.mapper"})
public class MybatisPluginsConfig {
	
	/**
     * 自动填充
     * @return
     */
    @Bean
    public MetaObjectHandler MetaObjectHandler() {
        return new MyMetaObjectHandler();
    }
    
    /**
     *  新的分页插件
     * @return
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
    	MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
    	interceptor.addInnerInterceptor(getPaginationInnerInterceptor());
    	interceptor.addInnerInterceptor(getOptimisticLockerInnerInterceptor());
        return interceptor;
    }
    
    /**
     * mybatis-plus分页插件
     */
    public PaginationInnerInterceptor getPaginationInnerInterceptor() {
    	PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
    	paginationInnerInterceptor.setDbType(DbType.MYSQL);
        // 设置请求的页面大于最大页后操作， true调回到首页，false 继续请求  默认false
//    	paginationInnerInterceptor.setOverflow(false);
        // 设置最大单页限制数量 不受限制
//    	paginationInnerInterceptor.setMaxLimit(500L);
        return paginationInnerInterceptor;
    }
    
    
    /**
     * 乐观锁插件
     * @return
     */
    public OptimisticLockerInnerInterceptor getOptimisticLockerInnerInterceptor() {
        return new OptimisticLockerInnerInterceptor();
    }
    

}
